/****************************************************************
 * Fulguro
 * Copyright (C) 2004 Christophe Clienti
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 ***************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "flgrCoreIO.h"
#include "flgrCoreVector.h"
#include "flgrCoreDispatch.h"
#include "flgrCoreArithDef.h"
#include "flgrCoreMeasureVector.h"

#define FLGR_MACRO_VECTOR_MEASURE_VOLUME(dtype,vtype)		\
  dtype *array=(dtype*)vec->array;				\
  vtype volume=0;						\
  int spp=vec->spp;						\
  int k;							\
								\
  FLGR_DECLARE_FUNCTION;					\
								\
  for(k=0; k<spp ; k++) {					\
    volume+=(vtype) (flgr_get_array_##dtype(array,k));		\
  }								\
  return volume






fgUINT64 flgr_vector_measure_volume_u64_fgBIT(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgBIT,fgUINT64);
}
fgUINT64 flgr_vector_measure_volume_u64_fgUINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT8,fgUINT64);
}
fgUINT64 flgr_vector_measure_volume_u64_fgUINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT16,fgUINT64);
}
fgUINT64 flgr_vector_measure_volume_u64_fgUINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT32,fgUINT64);
}
fgUINT64 flgr_vector_measure_volume_u64_fgUINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT64,fgUINT64);
}
fgUINT64 flgr_vector_measure_volume_u64_fgINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT8,fgUINT64);
}
fgUINT64 flgr_vector_measure_volume_u64_fgINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT16,fgUINT64);
}
fgUINT64 flgr_vector_measure_volume_u64_fgINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT32,fgUINT64);
}
fgUINT64 flgr_vector_measure_volume_u64_fgINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT64,fgUINT64);
}
fgUINT64 flgr_vector_measure_volume_u64_fgFLOAT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgFLOAT32,fgUINT64);
}
fgUINT64 flgr_vector_measure_volume_u64_fgFLOAT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgFLOAT64,fgUINT64);
}


////////////////////////////////////////////////////////////////////////////
/*! Measure vector volume (sum each elements)
 *
 *  @param vct : pointer to FLGR_Vector
 *  @returns fgUINT64 volume
 */
//////////////////////////////////////////////////////////////////
fgUINT64 flgr_vector_measure_volume_u64(FLGR_Vector *vec) {
  FLGR_DECLARE_FUNCTION;

  if(vec==NULL) {
    POST_ERROR("Null objects\n");
    return 0;
  }

  FLGR_FULL_FUNCTION_DISPATCH(0,vec->type,flgr_vector_measure_volume_u64,vec);
}





fgINT64 flgr_vector_measure_volume_s64_fgBIT(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgBIT,fgINT64);
}
fgINT64 flgr_vector_measure_volume_s64_fgUINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT8,fgINT64);
}
fgINT64 flgr_vector_measure_volume_s64_fgUINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT16,fgINT64);
}
fgINT64 flgr_vector_measure_volume_s64_fgUINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT32,fgINT64);
}
fgINT64 flgr_vector_measure_volume_s64_fgUINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT64,fgINT64);
}
fgINT64 flgr_vector_measure_volume_s64_fgINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT8,fgINT64);
}
fgINT64 flgr_vector_measure_volume_s64_fgINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT16,fgINT64);
}
fgINT64 flgr_vector_measure_volume_s64_fgINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT32,fgINT64);
}
fgINT64 flgr_vector_measure_volume_s64_fgINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT64,fgINT64);
}
fgINT64 flgr_vector_measure_volume_s64_fgFLOAT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgFLOAT32,fgINT64);
}
fgINT64 flgr_vector_measure_volume_s64_fgFLOAT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgFLOAT64,fgINT64);
}


////////////////////////////////////////////////////////////////////////////
/*! Measure vector volume (sum each elements)
 *
 *  @param vct : pointer to FLGR_Vector
 *  @returns fgINT64 volume
 */
//////////////////////////////////////////////////////////////////
fgINT64 flgr_vector_measure_volume_s64(FLGR_Vector *vec) {
  FLGR_DECLARE_FUNCTION;

  if(vec==NULL) {
    POST_ERROR("Null objects\n");
    return 0;
  }

  FLGR_FULL_FUNCTION_DISPATCH(0,vec->type,flgr_vector_measure_volume_s64,vec);
}







fgUINT32 flgr_vector_measure_volume_u32_fgBIT(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgBIT,fgUINT32);
}
fgUINT32 flgr_vector_measure_volume_u32_fgUINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT8,fgUINT32);
}
fgUINT32 flgr_vector_measure_volume_u32_fgUINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT16,fgUINT32);
}
fgUINT32 flgr_vector_measure_volume_u32_fgUINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT32,fgUINT32);
}
fgUINT32 flgr_vector_measure_volume_u32_fgUINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT64,fgUINT32);
}
fgUINT32 flgr_vector_measure_volume_u32_fgINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT8,fgUINT32);
}
fgUINT32 flgr_vector_measure_volume_u32_fgINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT16,fgUINT32);
}
fgUINT32 flgr_vector_measure_volume_u32_fgINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT32,fgUINT32);
}
fgUINT32 flgr_vector_measure_volume_u32_fgINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT64,fgUINT32);
}
fgUINT32 flgr_vector_measure_volume_u32_fgFLOAT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgFLOAT32,fgUINT32);
}
fgUINT32 flgr_vector_measure_volume_u32_fgFLOAT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgFLOAT64,fgUINT32);
}


////////////////////////////////////////////////////////////////////////////
/*! Measure vector volume (sum each elements)
 *
 *  @param vct : pointer to FLGR_Vector
 *  @returns fgUINT32 volume
 */
//////////////////////////////////////////////////////////////////
fgUINT32 flgr_vector_measure_volume_u32(FLGR_Vector *vec) {
  FLGR_DECLARE_FUNCTION;

  if(vec==NULL) {
    POST_ERROR("Null objects\n");
    return 0;
  }

  FLGR_FULL_FUNCTION_DISPATCH(0,vec->type,flgr_vector_measure_volume_u32,vec);
}




fgINT32 flgr_vector_measure_volume_s32_fgBIT(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgBIT,fgINT32);
}
fgINT32 flgr_vector_measure_volume_s32_fgUINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT8,fgINT32);
}
fgINT32 flgr_vector_measure_volume_s32_fgUINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT16,fgINT32);
}
fgINT32 flgr_vector_measure_volume_s32_fgUINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT32,fgINT32);
}
fgINT32 flgr_vector_measure_volume_s32_fgUINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT64,fgINT32);
}
fgINT32 flgr_vector_measure_volume_s32_fgINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT8,fgINT32);
}
fgINT32 flgr_vector_measure_volume_s32_fgINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT16,fgINT32);
}
fgINT32 flgr_vector_measure_volume_s32_fgINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT32,fgINT32);
}
fgINT32 flgr_vector_measure_volume_s32_fgINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT64,fgINT32);
}
fgINT32 flgr_vector_measure_volume_s32_fgFLOAT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgFLOAT32,fgINT32);
}
fgINT32 flgr_vector_measure_volume_s32_fgFLOAT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgFLOAT64,fgINT32);
}


////////////////////////////////////////////////////////////////////////////
/*! Measure vector volume (sum each elements)
 *
 *  @param vct : pointer to FLGR_Vector
 *  @returns fgINT32 volume
 */
//////////////////////////////////////////////////////////////////
fgINT32 flgr_vector_measure_volume_s32(FLGR_Vector *vec) {
  FLGR_DECLARE_FUNCTION;

  if(vec==NULL) {
    POST_ERROR("Null objects\n");
    return 0;
  }

  FLGR_FULL_FUNCTION_DISPATCH(0,vec->type,flgr_vector_measure_volume_s32,vec);
}






fgFLOAT32 flgr_vector_measure_volume_f32_fgBIT(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgBIT,fgFLOAT32);
}
fgFLOAT32 flgr_vector_measure_volume_f32_fgUINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT8,fgFLOAT32);
}
fgFLOAT32 flgr_vector_measure_volume_f32_fgUINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT16,fgFLOAT32);
}
fgFLOAT32 flgr_vector_measure_volume_f32_fgUINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT32,fgFLOAT32);
}
fgFLOAT32 flgr_vector_measure_volume_f32_fgUINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT64,fgFLOAT32);
}
fgFLOAT32 flgr_vector_measure_volume_f32_fgINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT8,fgFLOAT32);
}
fgFLOAT32 flgr_vector_measure_volume_f32_fgINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT16,fgFLOAT32);
}
fgFLOAT32 flgr_vector_measure_volume_f32_fgINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT32,fgFLOAT32);
}
fgFLOAT32 flgr_vector_measure_volume_f32_fgINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT64,fgFLOAT32);
}
fgFLOAT32 flgr_vector_measure_volume_f32_fgFLOAT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgFLOAT32,fgFLOAT32);
}
fgFLOAT32 flgr_vector_measure_volume_f32_fgFLOAT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgFLOAT64,fgFLOAT32);
}


////////////////////////////////////////////////////////////////////////////
/*! Measure vector volume (sum each elements)
 *
 *  @param vct : pointer to FLGR_Vector
 *  @returns fgFLOAT32 volume
 */
//////////////////////////////////////////////////////////////////
fgFLOAT32 flgr_vector_measure_volume_f32(FLGR_Vector *vec) {
  FLGR_DECLARE_FUNCTION;

  if(vec==NULL) {
    POST_ERROR("Null objects\n");
    return 0;
  }

  FLGR_FULL_FUNCTION_DISPATCH(0,vec->type,flgr_vector_measure_volume_f32,vec);
}






fgFLOAT64 flgr_vector_measure_volume_f64_fgBIT(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgBIT,fgFLOAT64);
}
fgFLOAT64 flgr_vector_measure_volume_f64_fgUINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT8,fgFLOAT64);
}
fgFLOAT64 flgr_vector_measure_volume_f64_fgUINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT16,fgFLOAT64);
}
fgFLOAT64 flgr_vector_measure_volume_f64_fgUINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT32,fgFLOAT64);
}
fgFLOAT64 flgr_vector_measure_volume_f64_fgUINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgUINT64,fgFLOAT64);
}
fgFLOAT64 flgr_vector_measure_volume_f64_fgINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT8,fgFLOAT64);
}
fgFLOAT64 flgr_vector_measure_volume_f64_fgINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT16,fgFLOAT64);
}
fgFLOAT64 flgr_vector_measure_volume_f64_fgINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT32,fgFLOAT64);
}
fgFLOAT64 flgr_vector_measure_volume_f64_fgINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgINT64,fgFLOAT64);
}
fgFLOAT64 flgr_vector_measure_volume_f64_fgFLOAT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgFLOAT32,fgFLOAT64);
}
fgFLOAT64 flgr_vector_measure_volume_f64_fgFLOAT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_VOLUME(fgFLOAT64,fgFLOAT64);
}


////////////////////////////////////////////////////////////////////////////
/*! Measure vector volume (sum each elements)
 *
 *  @param vct : pointer to FLGR_Vector
 *  @returns fgFLOAT64 volume
 */
//////////////////////////////////////////////////////////////////
fgFLOAT64 flgr_vector_measure_volume_f64(FLGR_Vector *vec) {
  FLGR_DECLARE_FUNCTION;

  if(vec==NULL) {
    POST_ERROR("Null objects\n");
    return 0;
  }

  FLGR_FULL_FUNCTION_DISPATCH(0,vec->type,flgr_vector_measure_volume_f64,vec);
}














//////////////////////////////////////////////////////////////////
// macro to measure vector norm
//////////////////////////////////////////////////////////////////

#define FLGR_MACRO_VECTOR_MEASURE_NORM(dtype,vtype)	\
  dtype *array=(dtype*)vec->array;			\
  vtype norm=0;						\
  vtype val=0;						\
  int spp=vec->spp;					\
  int k;						\
							\
  FLGR_DECLARE_FUNCTION;				\
							\
  for(k=0; k<spp ; k++) {				\
    val = (vtype) (flgr_get_array_##dtype(array,k));	\
    norm+= flgr_defop_square_##vtype(val);		\
  }							\
  return flgr_defop_sqrt_##vtype(norm);


fgUINT64 flgr_vector_measure_norm_u64_fgBIT(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgBIT,fgUINT64);
}
fgUINT64 flgr_vector_measure_norm_u64_fgUINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT8,fgUINT64);
}
fgUINT64 flgr_vector_measure_norm_u64_fgUINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT16,fgUINT64);
}
fgUINT64 flgr_vector_measure_norm_u64_fgUINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT32,fgUINT64);
}
fgUINT64 flgr_vector_measure_norm_u64_fgUINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT64,fgUINT64);
}
fgUINT64 flgr_vector_measure_norm_u64_fgINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT8,fgUINT64);
}
fgUINT64 flgr_vector_measure_norm_u64_fgINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT16,fgUINT64);
}
fgUINT64 flgr_vector_measure_norm_u64_fgINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT32,fgUINT64);
}
fgUINT64 flgr_vector_measure_norm_u64_fgINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT64,fgUINT64);
}
fgUINT64 flgr_vector_measure_norm_u64_fgFLOAT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgFLOAT32,fgUINT64);
}
fgUINT64 flgr_vector_measure_norm_u64_fgFLOAT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgFLOAT64,fgUINT64);
}


////////////////////////////////////////////////////////////////////////////
/*! Measure vector norm (sum each elements)
 *
 *  @param vct : pointer to FLGR_Vector
 *  @returns fgUINT64 norm
 */
//////////////////////////////////////////////////////////////////
fgUINT64 flgr_vector_measure_norm_u64(FLGR_Vector *vec) {
  FLGR_DECLARE_FUNCTION;

  if(vec==NULL) {
    POST_ERROR("Null objects\n");
    return 0;
  }

  FLGR_FULL_FUNCTION_DISPATCH(0,vec->type,flgr_vector_measure_norm_u64,vec);
}





fgINT64 flgr_vector_measure_norm_s64_fgBIT(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgBIT,fgINT64);
}
fgINT64 flgr_vector_measure_norm_s64_fgUINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT8,fgINT64);
}
fgINT64 flgr_vector_measure_norm_s64_fgUINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT16,fgINT64);
}
fgINT64 flgr_vector_measure_norm_s64_fgUINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT32,fgINT64);
}
fgINT64 flgr_vector_measure_norm_s64_fgUINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT64,fgINT64);
}
fgINT64 flgr_vector_measure_norm_s64_fgINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT8,fgINT64);
}
fgINT64 flgr_vector_measure_norm_s64_fgINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT16,fgINT64);
}
fgINT64 flgr_vector_measure_norm_s64_fgINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT32,fgINT64);
}
fgINT64 flgr_vector_measure_norm_s64_fgINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT64,fgINT64);
}
fgINT64 flgr_vector_measure_norm_s64_fgFLOAT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgFLOAT32,fgINT64);
}
fgINT64 flgr_vector_measure_norm_s64_fgFLOAT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgFLOAT64,fgINT64);
}


////////////////////////////////////////////////////////////////////////////
/*! Measure vector norm (sum each elements)
 *
 *  @param vct : pointer to FLGR_Vector
 *  @returns fgINT64 norm
 */
//////////////////////////////////////////////////////////////////
fgINT64 flgr_vector_measure_norm_s64(FLGR_Vector *vec) {
  FLGR_DECLARE_FUNCTION;

  if(vec==NULL) {
    POST_ERROR("Null objects\n");
    return 0;
  }

  FLGR_FULL_FUNCTION_DISPATCH(0,vec->type,flgr_vector_measure_norm_s64,vec);
}







fgUINT32 flgr_vector_measure_norm_u32_fgBIT(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgBIT,fgUINT32);
}
fgUINT32 flgr_vector_measure_norm_u32_fgUINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT8,fgUINT32);
}
fgUINT32 flgr_vector_measure_norm_u32_fgUINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT16,fgUINT32);
}
fgUINT32 flgr_vector_measure_norm_u32_fgUINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT32,fgUINT32);
}
fgUINT32 flgr_vector_measure_norm_u32_fgUINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT64,fgUINT32);
}
fgUINT32 flgr_vector_measure_norm_u32_fgINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT8,fgUINT32);
}
fgUINT32 flgr_vector_measure_norm_u32_fgINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT16,fgUINT32);
}
fgUINT32 flgr_vector_measure_norm_u32_fgINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT32,fgUINT32);
}
fgUINT32 flgr_vector_measure_norm_u32_fgINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT64,fgUINT32);
}
fgUINT32 flgr_vector_measure_norm_u32_fgFLOAT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgFLOAT32,fgUINT32);
}
fgUINT32 flgr_vector_measure_norm_u32_fgFLOAT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgFLOAT64,fgUINT32);
}


////////////////////////////////////////////////////////////////////////////
/*! Measure vector norm (sum each elements)
 *
 *  @param vct : pointer to FLGR_Vector
 *  @returns fgUINT32 norm
 */
//////////////////////////////////////////////////////////////////
fgUINT32 flgr_vector_measure_norm_u32(FLGR_Vector *vec) {
  FLGR_DECLARE_FUNCTION;

  if(vec==NULL) {
    POST_ERROR("Null objects\n");
    return 0;
  }

  FLGR_FULL_FUNCTION_DISPATCH(0,vec->type,flgr_vector_measure_norm_u32,vec);
}




fgINT32 flgr_vector_measure_norm_s32_fgBIT(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgBIT,fgINT32);
}
fgINT32 flgr_vector_measure_norm_s32_fgUINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT8,fgINT32);
}
fgINT32 flgr_vector_measure_norm_s32_fgUINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT16,fgINT32);
}
fgINT32 flgr_vector_measure_norm_s32_fgUINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT32,fgINT32);
}
fgINT32 flgr_vector_measure_norm_s32_fgUINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT64,fgINT32);
}
fgINT32 flgr_vector_measure_norm_s32_fgINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT8,fgINT32);
}
fgINT32 flgr_vector_measure_norm_s32_fgINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT16,fgINT32);
}
fgINT32 flgr_vector_measure_norm_s32_fgINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT32,fgINT32);
}
fgINT32 flgr_vector_measure_norm_s32_fgINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT64,fgINT32);
}
fgINT32 flgr_vector_measure_norm_s32_fgFLOAT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgFLOAT32,fgINT32);
}
fgINT32 flgr_vector_measure_norm_s32_fgFLOAT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgFLOAT64,fgINT32);
}


////////////////////////////////////////////////////////////////////////////
/*! Measure vector norm (sum each elements)
 *
 *  @param vct : pointer to FLGR_Vector
 *  @returns fgINT32 norm
 */
//////////////////////////////////////////////////////////////////
fgINT32 flgr_vector_measure_norm_s32(FLGR_Vector *vec) {
  FLGR_DECLARE_FUNCTION;

  if(vec==NULL) {
    POST_ERROR("Null objects\n");
    return 0;
  }

  FLGR_FULL_FUNCTION_DISPATCH(0,vec->type,flgr_vector_measure_norm_s32,vec);
}






fgFLOAT32 flgr_vector_measure_norm_f32_fgBIT(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgBIT,fgFLOAT32);
}
fgFLOAT32 flgr_vector_measure_norm_f32_fgUINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT8,fgFLOAT32);
}
fgFLOAT32 flgr_vector_measure_norm_f32_fgUINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT16,fgFLOAT32);
}
fgFLOAT32 flgr_vector_measure_norm_f32_fgUINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT32,fgFLOAT32);
}
fgFLOAT32 flgr_vector_measure_norm_f32_fgUINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT64,fgFLOAT32);
}
fgFLOAT32 flgr_vector_measure_norm_f32_fgINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT8,fgFLOAT32);
}
fgFLOAT32 flgr_vector_measure_norm_f32_fgINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT16,fgFLOAT32);
}
fgFLOAT32 flgr_vector_measure_norm_f32_fgINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT32,fgFLOAT32);
}
fgFLOAT32 flgr_vector_measure_norm_f32_fgINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT64,fgFLOAT32);
}
fgFLOAT32 flgr_vector_measure_norm_f32_fgFLOAT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgFLOAT32,fgFLOAT32);
}
fgFLOAT32 flgr_vector_measure_norm_f32_fgFLOAT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgFLOAT64,fgFLOAT32);
}


////////////////////////////////////////////////////////////////////////////
/*! Measure vector norm (sum each elements)
 *
 *  @param vct : pointer to FLGR_Vector
 *  @returns fgFLOAT32 norm
 */
//////////////////////////////////////////////////////////////////
fgFLOAT32 flgr_vector_measure_norm_f32(FLGR_Vector *vec) {
  FLGR_DECLARE_FUNCTION;

  if(vec==NULL) {
    POST_ERROR("Null objects\n");
    return 0;
  }

  FLGR_FULL_FUNCTION_DISPATCH(0,vec->type,flgr_vector_measure_norm_f32,vec);
}






fgFLOAT64 flgr_vector_measure_norm_f64_fgBIT(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgBIT,fgFLOAT64);
}
fgFLOAT64 flgr_vector_measure_norm_f64_fgUINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT8,fgFLOAT64);
}
fgFLOAT64 flgr_vector_measure_norm_f64_fgUINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT16,fgFLOAT64);
}
fgFLOAT64 flgr_vector_measure_norm_f64_fgUINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT32,fgFLOAT64);
}
fgFLOAT64 flgr_vector_measure_norm_f64_fgUINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgUINT64,fgFLOAT64);
}
fgFLOAT64 flgr_vector_measure_norm_f64_fgINT8(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT8,fgFLOAT64);
}
fgFLOAT64 flgr_vector_measure_norm_f64_fgINT16(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT16,fgFLOAT64);
}
fgFLOAT64 flgr_vector_measure_norm_f64_fgINT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT32,fgFLOAT64);
}
fgFLOAT64 flgr_vector_measure_norm_f64_fgINT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgINT64,fgFLOAT64);
}
fgFLOAT64 flgr_vector_measure_norm_f64_fgFLOAT32(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgFLOAT32,fgFLOAT64);
}
fgFLOAT64 flgr_vector_measure_norm_f64_fgFLOAT64(FLGR_Vector *vec) {
  FLGR_MACRO_VECTOR_MEASURE_NORM(fgFLOAT64,fgFLOAT64);
}


////////////////////////////////////////////////////////////////////////////
/*! Measure vector norm (sum each elements)
 *
 *  @param vct : pointer to FLGR_Vector
 *  @returns fgFLOAT64 norm
 */
//////////////////////////////////////////////////////////////////
fgFLOAT64 flgr_vector_measure_norm_f64(FLGR_Vector *vec) {
  FLGR_DECLARE_FUNCTION;

  if(vec==NULL) {
    POST_ERROR("Null objects\n");
    return 0;
  }

  FLGR_FULL_FUNCTION_DISPATCH(0,vec->type,flgr_vector_measure_norm_f64,vec);
}



















#define FLGR_MACRO_VECTOR_MEASURE_MIN(dtype)				\
  dtype *array=(dtype*)vec->array;					\
  dtype _min;								\
  int spp=vec->spp;							\
  int k;								\
									\
  FLGR_DECLARE_FUNCTION;						\
									\
  _min=flgr_get_array_##dtype(array,0);					\
									\
  for(k=1 ; k<spp ; k++) {						\
    _min = flgr_defop_inf_##dtype(_min,flgr_get_array_##dtype(array,k)); \
  }									\
									\
  *min = _min

void flgr_vector_measure_min_fgBIT(FLGR_Vector *vec, fgBIT *min) {
  FLGR_MACRO_VECTOR_MEASURE_MIN(fgBIT);
}
void flgr_vector_measure_min_fgUINT8(FLGR_Vector *vec, fgUINT8 *min) {
  FLGR_MACRO_VECTOR_MEASURE_MIN(fgUINT8);
}
void flgr_vector_measure_min_fgUINT16(FLGR_Vector *vec, fgUINT16 *min) {
  FLGR_MACRO_VECTOR_MEASURE_MIN(fgUINT16);
}
void flgr_vector_measure_min_fgUINT32(FLGR_Vector *vec, fgUINT32 *min) {
  FLGR_MACRO_VECTOR_MEASURE_MIN(fgUINT32);
}
void flgr_vector_measure_min_fgUINT64(FLGR_Vector *vec, fgUINT64 *min) {
  FLGR_MACRO_VECTOR_MEASURE_MIN(fgUINT64);
}
void flgr_vector_measure_min_fgINT8(FLGR_Vector *vec, fgINT8 *min) {
  FLGR_MACRO_VECTOR_MEASURE_MIN(fgINT8);
}
void flgr_vector_measure_min_fgINT16(FLGR_Vector *vec, fgINT16 *min) {
  FLGR_MACRO_VECTOR_MEASURE_MIN(fgINT16);
}
void flgr_vector_measure_min_fgINT32(FLGR_Vector *vec, fgINT32 *min) {
  FLGR_MACRO_VECTOR_MEASURE_MIN(fgINT32);
}
void flgr_vector_measure_min_fgINT64(FLGR_Vector *vec, fgINT64 *min) {
  FLGR_MACRO_VECTOR_MEASURE_MIN(fgINT64);
}
void flgr_vector_measure_min_fgFLOAT32(FLGR_Vector *vec, fgFLOAT32 *min) {
  FLGR_MACRO_VECTOR_MEASURE_MIN(fgFLOAT32);
}
void flgr_vector_measure_min_fgFLOAT64(FLGR_Vector *vec, fgFLOAT64 *min) {
  FLGR_MACRO_VECTOR_MEASURE_MIN(fgFLOAT64);
}


////////////////////////////////////////////////////////////////////////////
/*! Measure vector min
 *  @param vct : pointer to FLGR_Vector
 *  @param min : minimum value obtained
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr_vector_measure_min(FLGR_Vector *vec, void *min) {
  FLGR_DECLARE_FUNCTION;

  if(vec==NULL) {
    POST_ERROR("Null objects\n");
    return FLGR_RET_NULL_OBJECT;
  }

  FLGR_FULL_DISPATCH_CONST_PTR_PROCEDURE(vec->type,flgr_vector_measure_min,min,vec);

}











#define FLGR_MACRO_VECTOR_MEASURE_MAX(dtype)				\
  dtype *array=(dtype*)vec->array;					\
  dtype _max=flgr_get_array_##dtype(array,0);				\
  int spp=vec->spp;							\
  int k;								\
									\
  FLGR_DECLARE_FUNCTION;						\
									\
  for(k=1; k<spp ; k++) {						\
    _max = flgr_defop_sup_##dtype(_max,flgr_get_array_##dtype(array,k)); \
  }									\
  *max = _max

void flgr_vector_measure_max_fgBIT(FLGR_Vector *vec, fgBIT *max) {
  FLGR_MACRO_VECTOR_MEASURE_MAX(fgBIT);
}
void flgr_vector_measure_max_fgUINT8(FLGR_Vector *vec, fgUINT8 *max) {
  FLGR_MACRO_VECTOR_MEASURE_MAX(fgUINT8);
}
void flgr_vector_measure_max_fgUINT16(FLGR_Vector *vec, fgUINT16 *max) {
  FLGR_MACRO_VECTOR_MEASURE_MAX(fgUINT16);
}
void flgr_vector_measure_max_fgUINT32(FLGR_Vector *vec, fgUINT32 *max) {
  FLGR_MACRO_VECTOR_MEASURE_MAX(fgUINT32);
}
void flgr_vector_measure_max_fgUINT64(FLGR_Vector *vec, fgUINT64 *max) {
  FLGR_MACRO_VECTOR_MEASURE_MAX(fgUINT64);
}
void flgr_vector_measure_max_fgINT8(FLGR_Vector *vec, fgINT8 *max) {
  FLGR_MACRO_VECTOR_MEASURE_MAX(fgINT8);
}
void flgr_vector_measure_max_fgINT16(FLGR_Vector *vec, fgINT16 *max) {
  FLGR_MACRO_VECTOR_MEASURE_MAX(fgINT16);
}
void flgr_vector_measure_max_fgINT32(FLGR_Vector *vec, fgINT32 *max) {
  FLGR_MACRO_VECTOR_MEASURE_MAX(fgINT32);
}
void flgr_vector_measure_max_fgINT64(FLGR_Vector *vec, fgINT64 *max) {
  FLGR_MACRO_VECTOR_MEASURE_MAX(fgINT64);
}
void flgr_vector_measure_max_fgFLOAT32(FLGR_Vector *vec, fgFLOAT32 *max) {
  FLGR_MACRO_VECTOR_MEASURE_MAX(fgFLOAT32);
}
void flgr_vector_measure_max_fgFLOAT64(FLGR_Vector *vec, fgFLOAT64 *max) {
  FLGR_MACRO_VECTOR_MEASURE_MAX(fgFLOAT64);
}


////////////////////////////////////////////////////////////////////////////
/*! Measure vector max
 *  @param vct : pointer to FLGR_Vector
 *  @param max : maximum value obtained
 *  @returns FLGR_RET_OK, ...
 */
//////////////////////////////////////////////////////////////////
FLGR_Ret flgr_vector_measure_max(FLGR_Vector *vec, void *max) {
  FLGR_DECLARE_FUNCTION;

  if(vec==NULL) {
    POST_ERROR("Null objects\n");
    return FLGR_RET_NULL_OBJECT;
  }

  FLGR_FULL_DISPATCH_CONST_PTR_PROCEDURE(vec->type,flgr_vector_measure_max,max,vec);
}
